home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / fansi.zip / SETRAW.LC < prev    next >
Text File  |  1986-02-13  |  2KB  |  72 lines

  1. /*------ setraw.c ----------------------------------------------
  2. Lattice C routines which get and set the current raw/cooked state
  3. of a file, given its Lattice file descriptor.
  4. Useful when trying to obtain high console output speeds.
  5. ----------------------------------------------------------------*/
  6.  
  7. #include "\lc\dos.h"
  8. #define CARRY 0x1
  9. #define ERROR (-1)
  10. #define TRUE 1
  11. #define FALSE 0
  12.  
  13. extern _oserr;
  14.  
  15. /*---- getraw --------------------------------------------------
  16. Returns TRUE if file fd is a device in raw mode; FALSE otherwise.
  17. Returns ERROR, puts errorcode in _oserr, if DOS error.
  18. ----------------------------------------------------------------*/
  19. getraw(fd)
  20. int fd;
  21. {
  22.     union REGS inregs;
  23.     union REGS outregs;
  24.     int    flags;
  25.  
  26.     if (fd > 2) fd+=2;        /* convert to DOS fd */
  27.     inregs.x.bx = fd;
  28.     inregs.x.ax = 0x4400;        /* get file attributes */
  29.     flags = intdos(&inregs, &outregs);
  30.     if (flags & CARRY) {
  31.         _oserr = outregs.x.ax;
  32.         return -1;
  33.     }
  34.     return (outregs.x.dx & 0x20) ? TRUE : FALSE;
  35. }
  36.  
  37. /*---- setraw --------------------------------------------------
  38. Sets Raw state of file fd to raw_on (if file is not a device, does nothing).
  39. Returns zero if successful.
  40. Returns ERROR & errorcode in _oserr if DOS error.
  41. ----------------------------------------------------------------*/
  42. setraw(fd, raw_on)
  43. int fd, raw_on;
  44. {
  45.     union REGS inregs;
  46.     union REGS outregs;
  47.     int    flags;
  48.  
  49.     if (fd > 2) fd+=2;        /* convert to DOS fd */
  50.  
  51.     inregs.x.ax = 0x4400;        /* get file attributes */
  52.     inregs.x.bx = fd;
  53.     flags = intdos(&inregs, &outregs);
  54.     if (flags & CARRY) {
  55.         _oserr = outregs.x.ax;
  56.         return ERROR;
  57.     }
  58.     if ((outregs.x.ax & 0x80) == 0)    /* return zero if not device */
  59.         return 0;
  60.  
  61.     outregs.x.ax = 0x4401;        /* set file attributes */
  62.     outregs.x.bx = fd;
  63.     outregs.x.dx &= 0xcf;        /* clear old raw bit & hi byte */
  64.     if (raw_on) outregs.x.dx |= 0x20;    /* maybe set new raw bit */
  65.     flags = intdos(&outregs, &inregs);
  66.     if (flags & CARRY) {
  67.         _oserr = inregs.x.ax;
  68.         return ERROR;
  69.     }
  70.     return 0;
  71. }
  72.